#include "common.h"

#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/wait.h>
int mysystem(const char *command)
{
	if(command == NULL)
	{
		err_sys("Input error!\n");
		return 127;
	}
	else
	{
		pid_t pid;
		pid_t child_pid;
		int status;

//		char *ps_argv[] = {, NULL};

		pid = fork();
		if(pid < 0)
		{
			err_sys("fork error !\n");
			return -1;
		}
		else if(pid == 0)
		{
			printf("child process\n");
			printf("Child pid : %d\n", getpid());
			printf("Child ppid : %d\n", getppid());
			exit(100);
		}
		else
		{
			printf("parent process\n");
			printf("parent pid : %d\n", getpid());
/*
			child_pid = wait(&status);
			printf("Child process pid : %d\n", child_pid);
			if(WIFEXITED(status) != 0)
			{
				printf("child process exited with code %d\n", WEXITSTATUS(status));
				return (WEXITSTATUS(status));
			}
			else
			{
				printf("child process exited abnormally\n");
			}
*/
			//execlp(/bin/sh, -C, command, NULL);
		}
	}
}

int main(void)
{
	mysystem("ls");
	return 0;
}
